<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>蓝源Eloan-P2P平台->用户注册</title>
    <link rel="stylesheet" href="/js/bootstrap-3.3.2-dist/css/bootstrap.css" type="text/css"/>
    <link rel="stylesheet" href="/css/core.css" type="text/css"/>
    <script type="text/javascript" src="/js/jquery/jquery-2.1.3.js"></script>
    <script type="text/javascript" src="/js/bootstrap-3.3.2-dist/js/bootstrap.js"></script>
    <script type="text/javascript" src="/js/plugins/jquery-validation/jquery.validate.js"></script>
    <script type="text/javascript" src="/js/plugins/jquery.form.js"></script>
    <script type="text/javascript" src="/js/jquery.bootstrap.min.js"></script>

    <style type="text/css">
        .el-register-form {
            width: 600px;
            margin-left: auto;
            margin-right: auto;
            margin-top: 20px;
        }

        .el-register-form .form-control {
            width: 220px;
            display: inline;
        }

        input[name='verifycode'] + label {
            position: absolute;
            top: 7px;
            left: 220px;
        }

        div.main {
            margin-top: 40px;
            margin-bottom: 67px;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            //自定义校验规则,手机号码
            $.validator.addMethod("mobile", function (value, element) {
                var regex = /^1[3|4|5|7|8][0-9]{9}$/;
                return regex.test(value);
            }, "手机号码格式错误");

            $("#registerForm").validate({
                rules: {
                    username: {
                        required: true,
                        mobile: 'mobile',
                        remote: "/checkUsernameExist"
                    },
                    password: {
                        required: true,
                        rangelength: [4, 16]
                    },
                    verifyCode: {
                        required: true
                    },
                    confirmPwd: {
                        required: true,
                        equalTo: "#password"
                    }
                }, messages: {
                    username: {
                        required: "手机号码不能为空",
                        remote: "该手机号码已经被注册"
                    },
                    password: {
                        required: "密码不能为空",
                        rangelength: "密码在4到16位之间"
                    },
                    verifyCode: {
                        required: "验证码不能为空"
                    },
                    confirmPwd: {
                        required: "确认密码不能为空",
                        equalTo: "两次密码不一致"
                    }
                },
                // ajax 提交表单
                submitHandler : function(form){
                    $(form).ajaxSubmit(function (data) {
                        if (data.success){
                            $.messager.confirm("提示", "注册成功, 点击跳转到登录页面", function () {
                                window.location.href = "/login.html";
                            })
                        } else {
                            $.messager.popup(data.msg);
                        }
                    })
                },

                // 校验失败样式
                errorClass : "text-danger",
                // 对校验失败的文本框高亮
                highlight : function (inputElement, errorClass) {
                    $(inputElement).closest(".form-group").addClass("has-error");
                },
                unhighlight : function (inputElement, errorClass) {
                    $(inputElement).closest(".form-group").removeClass("has-error").addClass("has-success");
                }

            });
            //发送验证码
            $("#sendVerifyCode").click(function () {
                //判断手机号码是否为空
                var phonewNumber = $("#phoneNumber").val();
                if (phonewNumber){
                    // 禁用当前按钮, 改变按钮上的文本
                    var currentBtn = $(this);
                    currentBtn.prop("disabled", true);
                    //发送ajax请 生成验证码
                    $.post("/sendVerifyCode", {phoneNumber : phonewNumber}, function (data) {
                        console.log(data);
                        if (data.success){
                            var countDown = 90; // 倒计时,
                            // 定时器, 每隔一秒去修改按钮的文本
                            var timer = window.setInterval(function () {
                                countDown--;
                                currentBtn.text(countDown + "秒之后重新发送");
                                if (countDown == 0) {
                                    currentBtn.text("发送验证码");
                                    currentBtn.prop("disabled", false);
                                    window.clearInterval(timer);
                                }
                            }, 1000);
                        } else {
                            $.messager.popup(data.msg);
                            currentBtn.prop("disabled", false);
                        }
                    }, "json")
                } else {
                    $.messager.popup("手机号码不能为空");
                }
            })


        });
    </script>
</head>
<body>
<!-- 网页头信息 -->
<div class="el-header">
    <div class="container" style="position: relative;">
        <ul class="nav navbar-nav navbar-right">
            <li><a href="/">首页</a></li>
            <li><a href="/login.html">登录</a></li>
            <li><a href="#">帮助</a></li>
        </ul>
    </div>
</div>

<!-- 网页导航 -->
<div class="navbar navbar-default el-navbar">
    <div class="container">
        <div class="navbar-header">
            <a href=""><img alt="Brand" src="/images/logo.png"></a>
            <span class="el-page-title">用户注册</span>
        </div>
    </div>
</div>

<!-- 网页内容 -->
<div class="container main">
    <form id="registerForm" class="form-horizontal el-register-form" action="/register" method="post">
        <p class="h4" style="margin: 10px 10px 20px;color:#999;">请填写注册信息，点击“提交注册”即可完成注册！</p>
        <div class="form-group">
            <label class="control-label col-sm-2">手机号码</label>
            <div class="col-sm-10">
                <input type="text" placeholder="手机号码" autocomplete="off" name="username" class="form-control" id="phoneNumber"/>
                <p class="help-block">请输入正确的手机号码</p>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">手机验证码</label>
            <div class="col-sm-10">
                <input type="text" placeholder="手机验证码" style="width: 100px" autocomplete="off" name="verifyCode" class="form-control" id="verifyCode"/>
                <button type="button" class="btn btn-success" id="sendVerifyCode">
                    发送验证码
                </button>
                <p class="help-block">请输入手机收到的验证码</p>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">密&emsp;码</label>
            <div class="col-sm-10">
                <input type="password" placeholder="密码" autocomplete="off" name="password" id="password" class="form-control"/>
                <p class="help-block">密码为4~16位字符组成,采用数字、字母、符号安全性更高</p>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">确认密码</label>
            <div class="col-sm-10">
                <input type="password" autocomplete="off" name="confirmPwd" class="form-control"/>
                <p class="help-block">请再次填写密码</p>
            </div>
        </div>
        <div class="form-gorup">
            <div class="col-sm-offset-2">
                <button type="submit" class="btn btn-success">
                    同意协议并注册
                </button>
                &emsp;&emsp;
                <a href="/login.html" class="text-primary">已有账号，马上登录</a>

                <p style="padding-left: 50px;margin-top: 15px;">
                    <a href="#">《使用协议说明书》</a>
                </p>
            </div>
        </div>
    </form>
</div>
<!-- 网页版权 -->
<div class="container-foot-2">
    <div class="context">
        <div class="left">
            <p>版权所有：叩丁狼教育</p>
            <p>广州总部：广州市天河区棠下涌东路大地工业区D栋六楼</p>
            <p>北京校区：北京昌平区沙河镇万家灯火装饰城2楼8077号</p>
            <p>上海校区：上海市青浦区华新镇华隆路1777号E通世界商务园华新园A座4楼402</p>
            <p>电&emsp;&emsp;话： 020-85628002&emsp;&emsp;
                邮箱：&emsp;service@wolfcode.cn</p>
            <p>
                <a href="http://www.miitbeian.gov.cn" style="color: #ffffff">ICP备案
                    ：粤ICP备字17147191号-1</a>
            </p>
        </div>
        <div class="right">
            <a target="_blank" href="#"><img src="/images/wx-hover.png" title="官方微信"></a>
            <a target="_blank" href="#"><img src="/images/xl-hover.png" title="官方微博"></a>
        </div>
        <div class="clearfix"></div>
    </div>
</div>
</body>
</html>